package leecode

import (
	"sort"
)

func ReconstructQueue(people [][]int) [][]int {
	//第一步,对二维数组按照第一列的大小排序
	sort.Slice(people, func(i, j int) bool {
		if people[i][0] == people[j][0] {
			//第一列相同 , 按照第二列进行升序排列
			return people[i][1] < people[j][1]
		}
		return people[i][0] < people[j][0]
	})
	//按照k进行插入
	for i, p := range people {
		copy(people[p[1]+1:i+1], people[p[1]:i+1]) // 空出一个位置
		people[p[1]] = p
	}
	return people
}
